#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Storage;

#endregion

namespace WindowsGame
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch batch;
        SpriteFont font;

        Scrolling scrolling;

        Texture2D shotTextureRight;
        Texture2D shotTextureLeft;

        Texture2D background;

        TileMap map;

        CharacterObject mCharacter;

        ShotManager mPlayerShotManager;

        EnemyObject mEnemy;

        Song song1;

        bool GamePaused;

        int elapsedTime;

        private FPS_Counter fpsCounter;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            this.Window.Title = "Test";

            font = Content.Load<SpriteFont>(@"SpriteFonts\Arial");
            song1 = Content.Load<Song>(@"Audio\music");
            MediaPlayer.Volume = 0.8f;
            MediaPlayer.Play(song1);

            Global.ScreenResolution = new Vector2(800, 600);

            scrolling = new Scrolling();
            scrolling.init(Content);

            GamePaused = false;

            graphics.PreferredBackBufferWidth = (int)Global.ScreenResolution.X;
            graphics.PreferredBackBufferHeight = (int)Global.ScreenResolution.Y;
            graphics.ApplyChanges();

            map = new TileMap();
            map.Init(Content);

            mCharacter = new CharacterObject(map);
            mCharacter.Bounds = new TileRect(65, 50, 32, 42);
            Global.Offset = new Vector2(Global.ScreenResolution.X / 2 - mCharacter.Bounds.Width / 2 - mCharacter.Bounds.X,
                                        Global.ScreenResolution.Y / 2 - mCharacter.Bounds.Height / 2 - mCharacter.Bounds.Y);

            mPlayerShotManager = new ShotManager();

            mEnemy = new EnemyObject(map);
            mEnemy.Bounds = new TileRect(120, 165, 32, 42);

            fpsCounter = new FPS_Counter(this);

            base.Initialize();
        }


        /// <summary>
        /// Load your graphics content.  If loadAllContent is true, you should
        /// load content from both ResourceManagementMode pools.  Otherwise, just
        /// load ResourceManagementMode.Manual content.
        /// </summary>
        /// <param name="loadAllContent">Which type of content to load.</param>
        protected override void LoadContent()
        {
            // character
            AnimatedSprite characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character walking left"), 1, 14, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.WalkingLeft, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character walking right"), 1, 14, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.WalkingRight, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character left"), 1, 1, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.NormalLeft, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character right"), 1, 1, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.NormalRight, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character crouch left"), 1, 1, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.CrouchedLeft, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character crouch right"), 1, 1, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.CrouchedRight, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling left"), 1, 1, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.JumpLeft, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling right"), 1, 1, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.JumpRight, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling left"), 1, 1, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.FallingLeft, characterMovement);

            characterMovement = new AnimatedSprite();
            characterMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling right"), 1, 1, 32, 42, 15);
            this.mCharacter.AnimationSprites.Add(CharacterObject.CharacterState.FallingRight, characterMovement);

            // Enemy
            AnimatedSprite enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character walking left"), 1, 14, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.WalkingLeft, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character walking right"), 1, 14, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.WalkingRight, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character left"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.NormalLeft, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character right"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.NormalRight, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character crouch left"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.CrouchedLeft, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character crouch right"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.CrouchedRight, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling left"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.JumpLeft, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling right"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.JumpRight, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling left"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.JumpUpLookingLeft, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling right"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.JumpUpLookingRight, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling left"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.FallingLeft, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling left"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.FallingLookingLeft, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling right"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.FallingRight, enemyMovement);

            enemyMovement = new AnimatedSprite();
            enemyMovement.LoadGraphic(Content.Load<Texture2D>(@"GFX\Character\character jump or falling right"), 1, 1, 32, 42, 15);
            this.mEnemy.AnimationSprites.Add(EnemyObject.EnemyState.FallingLookingRight, enemyMovement);

            //background
            background = Content.Load<Texture2D>(@"GFX\Background\purple_gradient");

            shotTextureRight = Content.Load<Texture2D>(@"GFX\Weapon\Shot Right");
            shotTextureLeft = Content.Load<Texture2D>(@"GFX\Weapon\Shot Left");

            batch = new SpriteBatch(graphics.GraphicsDevice);

            map.Load("");
        }


        /// <summary>
        /// Unload your graphics content.  If unloadAllContent is true, you should
        /// unload content from both ResourceManagementMode pools.  Otherwise, just
        /// unload ResourceManagementMode.Manual content.  Manual content will get
        /// Disposed by the GraphicsDevice during a Reset.
        /// </summary>
        /// <param name="unloadAllContent">Which type of content to unload.</param>
        protected override void UnloadContent()
        {
            Content.Unload();
        }

        /// <summary>
        /// Sets the new main character state depending on several alowed key combinations.
        /// </summary>
        /// <param name="keyboardState">Current key combinations.</param>
        /// <remarks>
        /// 
        /// Bit combinations:
        /// 
        /// 0000 1111
        ///      ||||
        ///      |||+-- Key Left
        ///      ||+--- Key Right
        ///      |+---- Key Up
        ///      +----- Key Down
        /// 
        /// Note:
        /// Folowing combinations aren't alowed in this state machine:
        /// 
        /// 1. 0011 (Left AND Right)
        /// 2. 1100 (Up AND Down)
        /// 
        /// </remarks>
        private void setCharacterStateByKey(KeyboardState keyboardState)
        {
            int newKeyState = 0;

            if (keyboardState.IsKeyDown(Keys.Left) == true)
            {
                newKeyState |= (int)CharacterObject.MainKeyStates.Left;
            }

            if (keyboardState.IsKeyDown(Keys.Right) == true)
            {
                newKeyState |= (int)CharacterObject.MainKeyStates.Right;
            }

            if ((newKeyState & 0x03) == 0x03)
            {
                newKeyState = 0;
            }

            if (keyboardState.IsKeyDown(Keys.Up) == true)
            {
                newKeyState |= (int)CharacterObject.MainKeyStates.Up;
            }

            if (keyboardState.IsKeyDown(Keys.Down) == true)
            {
                newKeyState |= (int)CharacterObject.MainKeyStates.Down;
            }

            if ((newKeyState & 0x0C) == 0x0C)
            {
                newKeyState = 0;
            }

            this.mCharacter.KeyStates = newKeyState;

            this.mCharacter.performMovement(map);

        }


        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Keyboard.GetState();

            elapsedTime += gameTime.ElapsedRealTime.Milliseconds;

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (elapsedTime > 500)
            {
                if (keyboardState.IsKeyDown(Keys.F12))
                {
                    graphics.ToggleFullScreen();
                    elapsedTime = 0;
                }

                if (keyboardState.IsKeyDown(Keys.F11))
                {
                    if (graphics.SynchronizeWithVerticalRetrace == true)
                    {
                        graphics.SynchronizeWithVerticalRetrace = false;
                        elapsedTime = 0;
                    }
                    else
                    {
                        graphics.SynchronizeWithVerticalRetrace = true;
                        elapsedTime = 0;
                    }
                }

                if (keyboardState.IsKeyDown(Keys.F10))
                {
                    if (GamePaused == true)
                    {
                        GamePaused = false;
                        elapsedTime = 0;
                    }
                    else
                    {
                        GamePaused = true;
                        elapsedTime = 0;
                    }
                }

                if (keyboardState.IsKeyDown(Keys.M))
                {
                    MediaPlayer.Play(song1);
                    elapsedTime = 0;
                }

                if (keyboardState.IsKeyDown(Keys.S))
                {
                    MediaPlayer.Stop();
                    elapsedTime = 0;
                }

                if (keyboardState.IsKeyDown(Keys.P))
                {
                    if (MediaPlayer.State == MediaState.Paused)
                    {
                        MediaPlayer.Resume();
                        elapsedTime = 0;
                    }
                    else
                    {
                        MediaPlayer.Pause();
                        elapsedTime = 0;
                    }

                }
            }

            if (GamePaused == false)
            {
                setCharacterStateByKey(keyboardState);

                scrolling.update(mCharacter.Vector);

                this.mCharacter.update((float)gameTime.ElapsedGameTime.TotalSeconds);

                if (keyboardState.IsKeyDown(Keys.Space) && mCharacter.State != CharacterObject.CharacterState.Dead)
                {
                    if (mCharacter.State == CharacterObject.CharacterState.CrouchedLeft ||
                        mCharacter.State == CharacterObject.CharacterState.FallingLeft ||
                        mCharacter.State == CharacterObject.CharacterState.JumpLeft ||
                        mCharacter.State == CharacterObject.CharacterState.NormalLeft ||
                        mCharacter.State == CharacterObject.CharacterState.WalkingLeft)
                    {
                        if (mCharacter.State == CharacterObject.CharacterState.CrouchedLeft)
                        {
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 24), shotTextureLeft, new Vector2(-14, 4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 24), shotTextureLeft, new Vector2(-12, 2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 24), shotTextureLeft, new Vector2(-10, 0), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 24), shotTextureLeft, new Vector2(-12, -2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 24), shotTextureLeft, new Vector2(-14, -4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                        }
                        else
                        {
                            if (mCharacter.State == CharacterObject.CharacterState.JumpLeft ||
                                mCharacter.State == CharacterObject.CharacterState.FallingLeft)
                            {
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 10), shotTextureLeft, new Vector2(-14, 4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 10), shotTextureLeft, new Vector2(-12, 2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 10), shotTextureLeft, new Vector2(-10, 0), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 10), shotTextureLeft, new Vector2(-12, -2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 10), shotTextureLeft, new Vector2(-14, -4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            }
                            else
                            {
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 14), shotTextureLeft, new Vector2(-14, 4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 14), shotTextureLeft, new Vector2(-12, 2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 14), shotTextureLeft, new Vector2(-10, 0), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 14), shotTextureLeft, new Vector2(-12, -2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X - shotTextureLeft.Width + 10, mCharacter.Bounds.Y + 14), shotTextureLeft, new Vector2(-14, -4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            }
                        }
                    }
                    else
                    {
                        if (mCharacter.State == CharacterObject.CharacterState.CrouchedRight)
                        {
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 24), shotTextureRight, new Vector2(14, 4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 24), shotTextureRight, new Vector2(12, 2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 24), shotTextureRight, new Vector2(10, 0), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 24), shotTextureRight, new Vector2(12, -2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 24), shotTextureRight, new Vector2(14, -4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                        }
                        else
                        {
                            if (mCharacter.State == CharacterObject.CharacterState.JumpRight ||
                                mCharacter.State == CharacterObject.CharacterState.FallingRight)
                            {
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 10), shotTextureRight, new Vector2(14, 4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 10), shotTextureRight, new Vector2(12, 2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 10), shotTextureRight, new Vector2(10, 0), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 10), shotTextureRight, new Vector2(12, -2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 10), shotTextureRight, new Vector2(14, -4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            }
                            else
                            {
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 14), shotTextureRight, new Vector2(14, 4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 14), shotTextureRight, new Vector2(12, 2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 14), shotTextureRight, new Vector2(10, 0), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 14), shotTextureRight, new Vector2(12, -2), (float)gameTime.ElapsedGameTime.TotalSeconds);
                                mPlayerShotManager.Add(new Vector2(mCharacter.Bounds.X + mCharacter.Bounds.Width - 10, mCharacter.Bounds.Y + 14), shotTextureRight, new Vector2(14, -4), (float)gameTime.ElapsedGameTime.TotalSeconds);
                            }
                        }
                    }
                }

                mPlayerShotManager.Update(map, mCharacter);

                mEnemy.Movement(map, mCharacter);
                this.mEnemy.update((float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.Add))
            {
                if (MediaPlayer.Volume <= 0.99f)
                {
                    MediaPlayer.Volume += 0.01f;
                }
                else
                {
                    MediaPlayer.Volume = 1;
                }
            }

            if (keyboardState.IsKeyDown(Keys.Subtract))
            {
                if (MediaPlayer.Volume >= 0.01f)
                {
                    MediaPlayer.Volume -= 0.01f;
                }
                else
                {
                    MediaPlayer.Volume = 0;
                }
            }
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.Black);

            batch.Begin(SpriteBlendMode.AlphaBlend);

            batch.Draw(background, new Rectangle(0, 0, (int)Global.ScreenResolution.X, (int)Global.ScreenResolution.Y), Color.White);
            scrolling.draw(batch);

            map.Draw(batch, mCharacter);

            this.mCharacter.Draw(batch);

            mPlayerShotManager.Draw(batch);

            this.mEnemy.Draw(batch);

            fpsCounter.Update(gameTime);

            batch.DrawString(font, "Character Vector X: " + mCharacter.Vector.X + " Y: " + mCharacter.Vector.Y, new Vector2(0, Global.ScreenResolution.Y - 20), Color.Yellow);
            batch.DrawString(font, "Character State: " + mCharacter.State, new Vector2(0, Global.ScreenResolution.Y - 40), Color.Yellow);
            batch.DrawString(font, "Character Position X: " + mCharacter.Bounds.X + " Y: " + mCharacter.Bounds.Y, new Vector2(0, Global.ScreenResolution.Y - 60), Color.Yellow);
            batch.DrawString(font, String.Format("Character KeyState: {0}", (int)mCharacter.KeyStates), new Vector2(0, Global.ScreenResolution.Y - 80), Color.Yellow);
            fpsCounter.Draw(batch, graphics.SynchronizeWithVerticalRetrace, 0, (int)Global.ScreenResolution.Y - 100);
            batch.DrawString(font, "Game paused: " + GamePaused, new Vector2(0, Global.ScreenResolution.Y - 120), Color.Yellow);
            batch.DrawString(font, "Offset X: " + Global.Offset.X + " Y: " + Global.Offset.Y, new Vector2(0, Global.ScreenResolution.Y - 140), Color.Yellow);
            int temp = mPlayerShotManager.ShotCount();
            batch.DrawString(font, "Shot Count: " + temp, new Vector2(0, Global.ScreenResolution.Y - 160), Color.Yellow);
            batch.DrawString(font, "Volume: " + Math.Round(MediaPlayer.Volume, 2) * 100 + "%", new Vector2(0, Global.ScreenResolution.Y - 180), Color.Yellow);


            batch.DrawString(font, "Enemy State: " + mEnemy.State, new Vector2(0, Global.ScreenResolution.Y - 220), Color.Yellow);
            batch.DrawString(font, "Enemy Position X: " + mEnemy.Bounds.X + " Y: " + mEnemy.Bounds.Y, new Vector2(0, Global.ScreenResolution.Y - 240), Color.Yellow);

            batch.End();

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}
